<template>
	<view class="navbar">
		<view class="navbar-fixed" :style="barstyle">
			<!-- 状态栏小程序撑起高度 -->
			<view :style="{height:statusBarHeight+'px'}" style="background-color: transparent;"></view>
			<view class="navbar-content"  :style="{height:navBarHeight+'px',width:100+'%',background:barstyle}">
				<!-- 左边 -->
				<view v-if="combakflag" class="combak">
					<u-icon name="arrow-left" :size="28" @click="combak" color="#fff"></u-icon>
				</view>
				<view v-if="lang" class="combak">
					<Lang></Lang>
				</view>
				<view class="" v-if="!combakflag"></view>
				<!-- 中间 -->
				<view v-if="title" class="title" :style="{color:Color?Color:'#000'}" style="text-align: center;">{{title}}</view>
				<!-- 右边 -->
				<view class="right"></view>
			</view>
		</view>
		<!-- 需要添加占位符高度  状态栏高度+导航栏高度（否则下面tab会塌陷）-->
		<view v-if="bottom" :style="{height: statusBarHeight+navBarHeight+'px'}"></view>
	</view>
</template>

<script>
	import Lang from "./Lang.vue"
	export default {
		name: 'navbar',
		props: ['title', 'bottom', 'indexflag', 'barstyle', 'combakflag', 'lang','Color'],
		components:{
			Lang
		},
		data() {
			return {
				statusBarHeight: 0,
				/* 状态栏高度 */
				navBarHeight: 45,
				/* 导航栏高度 */
				windowWidth: 375,
				/* 窗口宽度 */
				/* 设定状态栏默认高度 */
				val: '',
				/* 导航栏搜索框的值 */

			};
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
			storeValue() {
				return this.$store.state.userinfo;
			},
		},
		created() {
			// 获取手机系统信息
			const info = uni.getSystemInfoSync()
			// 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
			this.statusBarHeight = info.statusBarHeight
			this.windowWidth = info.windowWidth
			// 除了h5 app mp-alipay的情况下执行
			// #ifndef H5 || APP-PLUS || MP-ALIPAY
			// 获取胶囊的位置
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo);
			// (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
			this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info
				.statusBarHeight)
			this.windowWidth = menuButtonInfo.left
			// #endif
		},
		methods: {
			combak() {
				uni.navigateBack();
			},
			Personalcenter() {
				uni.$emit('openLeft')
			},
			changelang() {
				// console.log(this.langindex)
				if (this.langindex == 0) {
					this.langindex = 1;
					this.$i18n.locale = 'ug';
					this.$store.commit('Lang', 'ug')
				} else {
					this.langindex = 0;
					this.$i18n.locale = 'cn';
					this.$store.commit('Lang', 'cn')
				}

			}
		}
	}
</script>

<style lang="scss">
	.navbar {
		.navbar-fixed {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100%;
			

			.navbar-content {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 15px;
				height: 45px;
				box-sizing: border-box;

				.right {}


				.title {
					display: flex;
					color: $uni-color-title;
					width: 100%;
					justify-content: center;
					align-items: center;
					// font-size: $uni-font-size-base;
				}

			}

		}

	}
</style>